<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Rails::Generators::Base</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/github.css" type="text/css" media="screen" />
<script src="../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Class</span> 
            Rails::Generators::Base 
            
                <span class="parent">&lt; 
                    
                    Thor::Group
                    
                </span>
            
        </h1>
        <ul class="files">
            
            <li><a href="../../../files/railties/lib/rails/generators/base_rb.html">railties/lib/rails/generators/base.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>A</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Base.html#method-c-add_shebang_option-21">add_shebang_option!</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>B</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Base.html#method-c-banner">banner</a>,
              </li>
            
              
              <li>
                <a href="Base.html#method-c-base_name">base_name</a>,
              </li>
            
              
              <li>
                <a href="Base.html#method-c-base_root">base_root</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>D</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Base.html#method-c-default_aliases_for_option">default_aliases_for_option</a>,
              </li>
            
              
              <li>
                <a href="Base.html#method-c-default_for_option">default_for_option</a>,
              </li>
            
              
              <li>
                <a href="Base.html#method-c-default_generator_root">default_generator_root</a>,
              </li>
            
              
              <li>
                <a href="Base.html#method-c-default_source_root">default_source_root</a>,
              </li>
            
              
              <li>
                <a href="Base.html#method-c-default_value_for_option">default_value_for_option</a>,
              </li>
            
              
              <li>
                <a href="Base.html#method-c-desc">desc</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>G</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Base.html#method-c-generator_name">generator_name</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>H</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Base.html#method-c-hide-21">hide!</a>,
              </li>
            
              
              <li>
                <a href="Base.html#method-c-hook_for">hook_for</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>N</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Base.html#method-c-namespace">namespace</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>R</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Base.html#method-c-remove_hook_for">remove_hook_for</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>S</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Base.html#method-c-source_root">source_root</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>U</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Base.html#method-c-usage_path">usage_path</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  
    <!-- Includes -->
    <div class="sectiontitle">Included Modules</div>
    <ul>
      
        <li>
          
            Thor::Actions
          
        </li>
      
        <li>
          
            <a href="Actions.html">
              Rails::Generators::Actions
            </a>
          
        </li>
      
    </ul>
  



  

    

    

    


    


    <!-- Methods -->
    
      <div class="sectiontitle">Class Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-c-base_root">
            
              <b>base_root</b>()
            
            <a href="Base.html#method-c-base_root" name="method-c-base_root" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns the base root for a common set of generators. This is used to
dynamically guess the default source root.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-base_root_source')" id="l_method-c-base_root_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/5ad7f8ab418f0c760dbb584f7c78d94ce32e9ee3/railties/lib/rails/generators/base.rb#L219" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-base_root_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/generators/base.rb, line 219</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">base_root</span>
  <span class="ruby-constant">File</span>.<span class="ruby-identifier">dirname</span>(<span class="ruby-keyword">__FILE__</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-c-default_source_root">
            
              <b>default_source_root</b>()
            
            <a href="Base.html#method-c-default_source_root" name="method-c-default_source_root" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns the default source root for a given generator. This is used
internally by rails to set its generators source root. If you want to
customize your source root, you should use source_root.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-default_source_root_source')" id="l_method-c-default_source_root_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/5ad7f8ab418f0c760dbb584f7c78d94ce32e9ee3/railties/lib/rails/generators/base.rb#L210" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-default_source_root_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/generators/base.rb, line 210</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">default_source_root</span>
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">base_name</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">generator_name</span>
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">default_generator_root</span>
  <span class="ruby-identifier">path</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">default_generator_root</span>, <span class="ruby-string">'templates'</span>)
  <span class="ruby-identifier">path</span> <span class="ruby-keyword">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exists?</span>(<span class="ruby-identifier">path</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-c-desc">
            
              <b>desc</b>(description=nil)
            
            <a href="Base.html#method-c-desc" name="method-c-desc" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Tries to get the description from a USAGE file one folder above the source
root otherwise uses a default description.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-desc_source')" id="l_method-c-desc_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/5ad7f8ab418f0c760dbb584f7c78d94ce32e9ee3/railties/lib/rails/generators/base.rb#L32" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-desc_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/generators/base.rb, line 32</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">desc</span>(<span class="ruby-identifier">description</span>=<span class="ruby-keyword">nil</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">super</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">description</span>

  <span class="ruby-ivar">@desc</span> <span class="ruby-operator">||=</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">usage_path</span>
    <span class="ruby-constant">ERB</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">usage_path</span>)).<span class="ruby-identifier">result</span>(<span class="ruby-identifier">binding</span>)
  <span class="ruby-keyword">else</span>
    <span class="ruby-node">&quot;Description:\n    Create #{base_name.humanize.downcase} files for #{generator_name} generator.&quot;</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-c-hide-21">
            
              <b>hide!</b>()
            
            <a href="Base.html#method-c-hide-21" name="method-c-hide-21" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Convenience method to hide this generator from the available ones when
running rails generator command.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-hide-21_source')" id="l_method-c-hide-21_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/5ad7f8ab418f0c760dbb584f7c78d94ce32e9ee3/railties/lib/rails/generators/base.rb#L52" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-hide-21_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/generators/base.rb, line 52</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">hide!</span>
  <span class="ruby-constant">Rails</span><span class="ruby-operator">::</span><span class="ruby-constant">Generators</span>.<span class="ruby-identifier">hide_namespace</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">namespace</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-c-hook_for">
            
              <b>hook_for</b>(*names, &amp;block)
            
            <a href="Base.html#method-c-hook_for" name="method-c-hook_for" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Invoke a generator based on the value supplied by the user to the given
option named “name”. A class option is created when this method is invoked
and you can set a hash to customize it.</p>

<h4 id="method-c-hook_for-label-Examples">Examples</h4>

<pre class="ruby"><span class="ruby-keyword">module</span> <span class="ruby-constant">Rails</span><span class="ruby-operator">::</span><span class="ruby-constant">Generators</span>
  <span class="ruby-keyword">class</span> <span class="ruby-constant">ControllerGenerator</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">Base</span>
    <span class="ruby-identifier">hook_for</span> :<span class="ruby-identifier">test_framework</span>, <span class="ruby-identifier">aliases</span><span class="ruby-operator">:</span> <span class="ruby-string">&quot;-t&quot;</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>
</pre>

<p>The example above will create a test framework option and will invoke a
generator based on the user supplied value.</p>

<p>For example, if the user invoke the controller generator as:</p>

<pre>rails generate controller Account --test-framework=test_unit</pre>

<p>The controller generator will then try to invoke the following generators:</p>

<pre>&quot;rails:test_unit&quot;, &quot;test_unit:controller&quot;, &quot;test_unit&quot;</pre>

<p>Notice that “rails:generators:test_unit” could be loaded as well, what <a
href="../../Rails.html">Rails</a> looks for is the first and last parts of
the namespace. This is what allows any test framework to hook into <a
href="../../Rails.html">Rails</a> as long as it provides any of the hooks
above.</p>

<h4 id="method-c-hook_for-label-Options">Options</h4>

<p>The first and last part used to find the generator to be invoked are
guessed based on class invokes <a
href="Base.html#method-c-hook_for">::hook_for</a>, as noticed in the
example above. This can be customized with two options: :base and :as.</p>

<p>Let’s suppose you are creating a generator that needs to invoke the
controller generator from test unit. Your first attempt is:</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">AwesomeGenerator</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">Rails</span><span class="ruby-operator">::</span><span class="ruby-constant">Generators</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>
  <span class="ruby-identifier">hook_for</span> :<span class="ruby-identifier">test_framework</span>
<span class="ruby-keyword">end</span>
</pre>

<p>The lookup in this case for test_unit as input is:</p>

<pre>&quot;test_unit:awesome&quot;, &quot;test_unit&quot;</pre>

<p>Which is not the desired lookup. You can change it by providing the :as
option:</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">AwesomeGenerator</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">Rails</span><span class="ruby-operator">::</span><span class="ruby-constant">Generators</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>
  <span class="ruby-identifier">hook_for</span> :<span class="ruby-identifier">test_framework</span>, <span class="ruby-identifier">as</span><span class="ruby-operator">:</span> :<span class="ruby-identifier">controller</span>
<span class="ruby-keyword">end</span>
</pre>

<p>And now it will lookup at:</p>

<pre>&quot;test_unit:controller&quot;, &quot;test_unit&quot;</pre>

<p>Similarly, if you want it to also lookup in the rails namespace, you just
need to provide the :base value:</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">AwesomeGenerator</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">Rails</span><span class="ruby-operator">::</span><span class="ruby-constant">Generators</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>
  <span class="ruby-identifier">hook_for</span> :<span class="ruby-identifier">test_framework</span>, <span class="ruby-keyword">in</span><span class="ruby-operator">:</span> :<span class="ruby-identifier">rails</span>, <span class="ruby-identifier">as</span><span class="ruby-operator">:</span> :<span class="ruby-identifier">controller</span>
<span class="ruby-keyword">end</span>
</pre>

<p>And the lookup is exactly the same as previously:</p>

<pre>&quot;rails:test_unit&quot;, &quot;test_unit:controller&quot;, &quot;test_unit&quot;</pre>

<h4 id="method-c-hook_for-label-Switches">Switches</h4>

<p>All hooks come with switches for user interface. If you do not want to use
any test framework, you can do:</p>

<pre>rails generate controller Account --skip-test-framework</pre>

<p>Or similarly:</p>

<pre>rails generate controller Account --no-test-framework</pre>

<h4 id="method-c-hook_for-label-Boolean+hooks">Boolean hooks</h4>

<p>In some cases, you may want to provide a boolean hook. For example, webrat
developers might want to have webrat available on controller generator.
This can be achieved as:</p>

<pre>Rails::Generators::ControllerGenerator.hook_for :webrat, type: :boolean</pre>

<p>Then, if you want webrat to be invoked, just supply:</p>

<pre>rails generate controller Account --webrat</pre>

<p>The hooks lookup is similar as above:</p>

<pre>&quot;rails:generators:webrat&quot;, &quot;webrat:generators:controller&quot;, &quot;webrat&quot;</pre>

<h4 id="method-c-hook_for-label-Custom+invocations">Custom invocations</h4>

<p>You can also supply a block to <a
href="Base.html#method-c-hook_for">::hook_for</a> to customize how the hook
is going to be invoked. The block receives two arguments, an instance of
the current class and the class to be invoked.</p>

<p>For example, in the resource generator, the controller should be invoked
with a pluralized class name. But by default it is invoked with the same
name as the resource generator, which is singular. To change this, we can
give a block to customize how the controller can be invoked.</p>

<pre class="ruby"><span class="ruby-identifier">hook_for</span> :<span class="ruby-identifier">resource_controller</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">instance</span>, <span class="ruby-identifier">controller</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">instance</span>.<span class="ruby-identifier">invoke</span> <span class="ruby-identifier">controller</span>, [ <span class="ruby-identifier">instance</span>.<span class="ruby-identifier">name</span>.<span class="ruby-identifier">pluralize</span> ]
<span class="ruby-keyword">end</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-hook_for_source')" id="l_method-c-hook_for_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/5ad7f8ab418f0c760dbb584f7c78d94ce32e9ee3/railties/lib/rails/generators/base.rb#L165" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-hook_for_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/generators/base.rb, line 165</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">hook_for</span>(*<span class="ruby-identifier">names</span>, &amp;<span class="ruby-identifier">block</span>)
  <span class="ruby-identifier">options</span> = <span class="ruby-identifier">names</span>.<span class="ruby-identifier">extract_options!</span>
  <span class="ruby-identifier">in_base</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:in</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">base_name</span>
  <span class="ruby-identifier">as_hook</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:as</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">generator_name</span>

  <span class="ruby-identifier">names</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">name</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">defaults</span> = <span class="ruby-keyword">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:type</span>] <span class="ruby-operator">==</span> <span class="ruby-value">:boolean</span>
      { }
    <span class="ruby-keyword">elsif</span> [<span class="ruby-keyword">true</span>, <span class="ruby-keyword">false</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">default_value_for_option</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span>))
      { <span class="ruby-identifier">banner</span><span class="ruby-operator">:</span> <span class="ruby-string">&quot;&quot;</span> }
    <span class="ruby-keyword">else</span>
      { <span class="ruby-identifier">desc</span><span class="ruby-operator">:</span> <span class="ruby-node">&quot;#{name.to_s.humanize} to be invoked&quot;</span>, <span class="ruby-identifier">banner</span><span class="ruby-operator">:</span> <span class="ruby-string">&quot;NAME&quot;</span> }
    <span class="ruby-keyword">end</span>

    <span class="ruby-keyword">unless</span> <span class="ruby-identifier">class_options</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-identifier">name</span>)
      <span class="ruby-identifier">class_option</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">defaults</span>.<span class="ruby-identifier">merge!</span>(<span class="ruby-identifier">options</span>))
    <span class="ruby-keyword">end</span>

    <span class="ruby-identifier">hooks</span>[<span class="ruby-identifier">name</span>] = [ <span class="ruby-identifier">in_base</span>, <span class="ruby-identifier">as_hook</span> ]
    <span class="ruby-identifier">invoke_from_option</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span>, &amp;<span class="ruby-identifier">block</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-c-namespace">
            
              <b>namespace</b>(name=nil)
            
            <a href="Base.html#method-c-namespace" name="method-c-namespace" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Convenience method to get the namespace from the class name. It’s the same
as Thor default except that the Generator at the end of the class is
removed.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-namespace_source')" id="l_method-c-namespace_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/5ad7f8ab418f0c760dbb584f7c78d94ce32e9ee3/railties/lib/rails/generators/base.rb#L45" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-namespace_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/generators/base.rb, line 45</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">namespace</span>(<span class="ruby-identifier">name</span>=<span class="ruby-keyword">nil</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">super</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">name</span>
  <span class="ruby-ivar">@namespace</span> <span class="ruby-operator">||=</span> <span class="ruby-keyword">super</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp">/_generator$/</span>, <span class="ruby-string">''</span>).<span class="ruby-identifier">sub</span>(<span class="ruby-regexp">/:generators:/</span>, <span class="ruby-string">':'</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-c-remove_hook_for">
            
              <b>remove_hook_for</b>(*names)
            
            <a href="Base.html#method-c-remove_hook_for" name="method-c-remove_hook_for" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Remove a previously added hook.</p>

<pre>remove_hook_for :orm</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-remove_hook_for_source')" id="l_method-c-remove_hook_for_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/5ad7f8ab418f0c760dbb584f7c78d94ce32e9ee3/railties/lib/rails/generators/base.rb#L191" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-remove_hook_for_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/generators/base.rb, line 191</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">remove_hook_for</span>(*<span class="ruby-identifier">names</span>)
  <span class="ruby-identifier">remove_invocation</span>(*<span class="ruby-identifier">names</span>)

  <span class="ruby-identifier">names</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">name</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">hooks</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">name</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-c-source_root">
            
              <b>source_root</b>(path=nil)
            
            <a href="Base.html#method-c-source_root" name="method-c-source_root" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns the source root for this generator using <a
href="Base.html#method-c-default_source_root">::default_source_root</a> as
default.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-source_root_source')" id="l_method-c-source_root_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/5ad7f8ab418f0c760dbb584f7c78d94ce32e9ee3/railties/lib/rails/generators/base.rb#L25" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-source_root_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/generators/base.rb, line 25</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">source_root</span>(<span class="ruby-identifier">path</span>=<span class="ruby-keyword">nil</span>)
  <span class="ruby-ivar">@_source_root</span> = <span class="ruby-identifier">path</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">path</span>
  <span class="ruby-ivar">@_source_root</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">default_source_root</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
              
      <div class="sectiontitle">Class Protected methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-c-add_shebang_option-21">
            
              <b>add_shebang_option!</b>()
            
            <a href="Base.html#method-c-add_shebang_option-21" name="method-c-add_shebang_option-21" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Small macro to add ruby as an option to the generator with proper default
value plus an instance helper method called shebang.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-add_shebang_option-21_source')" id="l_method-c-add_shebang_option-21_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/5ad7f8ab418f0c760dbb584f7c78d94ce32e9ee3/railties/lib/rails/generators/base.rb#L345" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-add_shebang_option-21_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/generators/base.rb, line 345</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">add_shebang_option!</span>
  <span class="ruby-identifier">class_option</span> <span class="ruby-value">:ruby</span>, <span class="ruby-identifier">type</span><span class="ruby-operator">:</span> <span class="ruby-value">:string</span>, <span class="ruby-identifier">aliases</span><span class="ruby-operator">:</span> <span class="ruby-string">&quot;-r&quot;</span>, <span class="ruby-identifier">default</span><span class="ruby-operator">:</span> <span class="ruby-constant">Thor</span><span class="ruby-operator">::</span><span class="ruby-constant">Util</span>.<span class="ruby-identifier">ruby_command</span>,
                      <span class="ruby-identifier">desc</span><span class="ruby-operator">:</span> <span class="ruby-string">&quot;Path to the Ruby binary of your choice&quot;</span>, <span class="ruby-identifier">banner</span><span class="ruby-operator">:</span> <span class="ruby-string">&quot;PATH&quot;</span>

  <span class="ruby-identifier">no_tasks</span> {
    <span class="ruby-identifier">define_method</span> <span class="ruby-value">:shebang</span> <span class="ruby-keyword">do</span>
      <span class="ruby-ivar">@shebang</span> <span class="ruby-operator">||=</span> <span class="ruby-keyword">begin</span>
        <span class="ruby-identifier">command</span> = <span class="ruby-keyword">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:ruby</span>] <span class="ruby-operator">==</span> <span class="ruby-constant">Thor</span><span class="ruby-operator">::</span><span class="ruby-constant">Util</span>.<span class="ruby-identifier">ruby_command</span>
          <span class="ruby-node">&quot;/usr/bin/env #{File.basename(Thor::Util.ruby_command)}&quot;</span>
        <span class="ruby-keyword">else</span>
          <span class="ruby-identifier">options</span>[<span class="ruby-value">:ruby</span>]
        <span class="ruby-keyword">end</span>
        <span class="ruby-node">&quot;#!#{command}&quot;</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
  }
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-c-banner">
            
              <b>banner</b>()
            
            <a href="Base.html#method-c-banner" name="method-c-banner" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Use <a href="../../Rails.html">Rails</a> default banner.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-banner_source')" id="l_method-c-banner_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/5ad7f8ab418f0c760dbb584f7c78d94ce32e9ee3/railties/lib/rails/generators/base.rb#L274" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-banner_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/generators/base.rb, line 274</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">banner</span>
  <span class="ruby-node">&quot;rails generate #{namespace.sub(/^rails:/,'')} #{self.arguments.map{ |a| a.usage }.join(' ')} [options]&quot;</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp">/\s+/</span>, <span class="ruby-string">' '</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-c-base_name">
            
              <b>base_name</b>()
            
            <a href="Base.html#method-c-base_name" name="method-c-base_name" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Sets the <a href="Base.html#method-c-base_name">::base_name</a> taking into
account the current class namespace.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-base_name_source')" id="l_method-c-base_name_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/5ad7f8ab418f0c760dbb584f7c78d94ce32e9ee3/railties/lib/rails/generators/base.rb#L279" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-base_name_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/generators/base.rb, line 279</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">base_name</span>
  <span class="ruby-ivar">@base_name</span> <span class="ruby-operator">||=</span> <span class="ruby-keyword">begin</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">base</span> = <span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">'::'</span>).<span class="ruby-identifier">first</span>
      <span class="ruby-identifier">base</span>.<span class="ruby-identifier">underscore</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-c-default_aliases_for_option">
            
              <b>default_aliases_for_option</b>(name, options)
            
            <a href="Base.html#method-c-default_aliases_for_option" name="method-c-default_aliases_for_option" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Return default aliases for the option name given doing a lookup in
Rails::Generators.aliases.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-default_aliases_for_option_source')" id="l_method-c-default_aliases_for_option_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/5ad7f8ab418f0c760dbb584f7c78d94ce32e9ee3/railties/lib/rails/generators/base.rb#L306" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-default_aliases_for_option_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/generators/base.rb, line 306</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">default_aliases_for_option</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span>)
  <span class="ruby-identifier">default_for_option</span>(<span class="ruby-constant">Rails</span><span class="ruby-operator">::</span><span class="ruby-constant">Generators</span>.<span class="ruby-identifier">aliases</span>, <span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span>, <span class="ruby-identifier">options</span>[<span class="ruby-value">:aliases</span>])
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-c-default_for_option">
            
              <b>default_for_option</b>(config, name, options, default)
            
            <a href="Base.html#method-c-default_for_option" name="method-c-default_for_option" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Return default for the option name given doing a lookup in config.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-default_for_option_source')" id="l_method-c-default_for_option_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/5ad7f8ab418f0c760dbb584f7c78d94ce32e9ee3/railties/lib/rails/generators/base.rb#L311" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-default_for_option_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/generators/base.rb, line 311</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">default_for_option</span>(<span class="ruby-identifier">config</span>, <span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span>, <span class="ruby-identifier">default</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">generator_name</span> <span class="ruby-keyword">and</span> <span class="ruby-identifier">c</span> = <span class="ruby-identifier">config</span>[<span class="ruby-identifier">generator_name</span>.<span class="ruby-identifier">to_sym</span>] <span class="ruby-keyword">and</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-identifier">name</span>)
    <span class="ruby-identifier">c</span>[<span class="ruby-identifier">name</span>]
  <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">base_name</span> <span class="ruby-keyword">and</span> <span class="ruby-identifier">c</span> = <span class="ruby-identifier">config</span>[<span class="ruby-identifier">base_name</span>.<span class="ruby-identifier">to_sym</span>] <span class="ruby-keyword">and</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-identifier">name</span>)
    <span class="ruby-identifier">c</span>[<span class="ruby-identifier">name</span>]
  <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">config</span>[<span class="ruby-value">:rails</span>].<span class="ruby-identifier">key?</span>(<span class="ruby-identifier">name</span>)
    <span class="ruby-identifier">config</span>[<span class="ruby-value">:rails</span>][<span class="ruby-identifier">name</span>]
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">default</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-c-default_generator_root">
            
              <b>default_generator_root</b>()
            
            <a href="Base.html#method-c-default_generator_root" name="method-c-default_generator_root" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-default_generator_root_source')" id="l_method-c-default_generator_root_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/5ad7f8ab418f0c760dbb584f7c78d94ce32e9ee3/railties/lib/rails/generators/base.rb#L371" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-default_generator_root_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/generators/base.rb, line 371</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">default_generator_root</span>
  <span class="ruby-identifier">path</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">base_name</span>, <span class="ruby-identifier">generator_name</span>), <span class="ruby-identifier">base_root</span>)
  <span class="ruby-identifier">path</span> <span class="ruby-keyword">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exists?</span>(<span class="ruby-identifier">path</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-c-default_value_for_option">
            
              <b>default_value_for_option</b>(name, options)
            
            <a href="Base.html#method-c-default_value_for_option" name="method-c-default_value_for_option" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Return the default value for the option name given doing a lookup in
Rails::Generators.options.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-default_value_for_option_source')" id="l_method-c-default_value_for_option_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/5ad7f8ab418f0c760dbb584f7c78d94ce32e9ee3/railties/lib/rails/generators/base.rb#L300" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-default_value_for_option_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/generators/base.rb, line 300</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">default_value_for_option</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span>)
  <span class="ruby-identifier">default_for_option</span>(<span class="ruby-constant">Rails</span><span class="ruby-operator">::</span><span class="ruby-constant">Generators</span>.<span class="ruby-identifier">options</span>, <span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span>, <span class="ruby-identifier">options</span>[<span class="ruby-value">:default</span>])
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-c-generator_name">
            
              <b>generator_name</b>()
            
            <a href="Base.html#method-c-generator_name" name="method-c-generator_name" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Removes the namespaces and get the generator name. For example,
Rails::Generators::ModelGenerator will return “model” as generator name.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-generator_name_source')" id="l_method-c-generator_name_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/5ad7f8ab418f0c760dbb584f7c78d94ce32e9ee3/railties/lib/rails/generators/base.rb#L289" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-generator_name_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/generators/base.rb, line 289</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">generator_name</span>
  <span class="ruby-ivar">@generator_name</span> <span class="ruby-operator">||=</span> <span class="ruby-keyword">begin</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">generator</span> = <span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">'::'</span>).<span class="ruby-identifier">last</span>
      <span class="ruby-identifier">generator</span>.<span class="ruby-identifier">sub!</span>(<span class="ruby-regexp">/Generator$/</span>, <span class="ruby-string">''</span>)
      <span class="ruby-identifier">generator</span>.<span class="ruby-identifier">underscore</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-c-usage_path">
            
              <b>usage_path</b>()
            
            <a href="Base.html#method-c-usage_path" name="method-c-usage_path" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-usage_path_source')" id="l_method-c-usage_path_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/5ad7f8ab418f0c760dbb584f7c78d94ce32e9ee3/railties/lib/rails/generators/base.rb#L363" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-usage_path_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/generators/base.rb, line 363</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">usage_path</span>
  <span class="ruby-identifier">paths</span> = [
    <span class="ruby-identifier">source_root</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-string">&quot;../USAGE&quot;</span>, <span class="ruby-identifier">source_root</span>),
    <span class="ruby-identifier">default_generator_root</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">default_generator_root</span>, <span class="ruby-string">&quot;USAGE&quot;</span>)
  ]
  <span class="ruby-identifier">paths</span>.<span class="ruby-identifier">compact</span>.<span class="ruby-identifier">detect</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">path</span><span class="ruby-operator">|</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exists?</span> <span class="ruby-identifier">path</span> }
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                        </div>

    </div>
  </body>
</html>    